import 'dart:convert';

import 'NewsEntity.dart';
import 'TypeBeanEntity.dart';

BannerEntity bannerEntityFromJson(String str) => BannerEntity.fromJson(json.decode(str));

String bannerEntityToJson(BannerEntity data) => json.encode(data.toJson());

class BannerEntity {
  List<ListBannerElement> list;
  List<TypeBeanEntity> indexTypeList;

  BannerEntity({
    required this.list,
    required this.indexTypeList,
  });

  factory BannerEntity.fromJson(Map<String, dynamic> json) {
    print("BannerEntity ${json.toString()}");
    return BannerEntity(
      list: List<ListBannerElement>.from(json["list"].map((x) => ListBannerElement.fromJson(x))),
      indexTypeList: List<TypeBeanEntity>.from(json["index_type_all"].map((x) => TypeBeanEntity.fromJson(x))),
    );
  }

  Map<String, dynamic> toJson() => {
    "list": List<dynamic>.from(list.map((x) => x.toJson())),
  };
}

class ListBannerElement {
  int id;
  String? href;
  String? url;
  int? articleId;
  ListNewsElement? article;

  ListBannerElement({
    required this.id,
    required this.href,
    required this.url,
    required this.articleId,
    required this.article
  });

  factory ListBannerElement.fromJson(Map<String, dynamic> json) => ListBannerElement(
    id: json["id"],
    href: json["href"].toString(),
    url: json["url"],
    articleId: json["article_id"],
    article: json["article"]==null?null:ListNewsElement.fromJson(json["article"]),
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "href": href,
    "url": url
  };
}
